package com.example.money.test;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.money.test.Async.TextAsyncTask;
import com.example.money.test.HideToobar.BehaviorOneActivity;
import com.example.money.test.HideToobar.BehaviorTwoActivity;
import com.example.money.test.HideToobar.CollapsingToolbarActivity;
import com.example.money.test.HideToobar.CoordicatorActivity;
import com.example.money.test.RecyclerViewStudy.RecyleActivity;
import com.example.money.test.TabLayout.TabLayoutActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Button mButton;
    private Button mLoadImage;
    private Button mCardView;
    private Button mNoti;
    private Toolbar mToolbar;
    private Button mTo;
    private Button mTextInput;
    private Button mTabLayout;
    private Button mNavigation;
    private Button mHideToolbar;
    private Button mHideToolbar2;
    private Button mBehavior1;
    private Button mBehavior2;
    String TAG = "ActivtyA";
    //定义一个动作
    private final String ACTION_NAME = "测试广播";
    //1.初始化一个reciever
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            //4.处理一个广播
            String str = intent.getAction();
            Toast.makeText(MainActivity.this,"我要处理这个"+str,Toast.LENGTH_LONG).show();
        }
    };

    private Button mRecycle;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d(TAG, "onCreate: Acreate");

        mButton = findViewById(R.id.button);
        mLoadImage = findViewById(R.id.showimage);
        mRecycle = findViewById(R.id.id_recycle);
        mCardView = findViewById(R.id.id_cardview);
        mNoti = findViewById(R.id.id_noti);
        mToolbar = this.findViewById(R.id.toolbar);
        mTo = findViewById(R.id.id_toolbar);
        mTextInput = findViewById(R.id.id_textinput);
        mTabLayout = findViewById(R.id.id_tabLayout);
        mNavigation = findViewById(R.id.id_navigation);
        mHideToolbar = findViewById(R.id.id_hideToolbar);
        mHideToolbar2 = findViewById(R.id.id_collapsing);
        mBehavior1 = findViewById(R.id.id_behavior_one);
        mBehavior2 = findViewById(R.id.id_behavior_two);

        setSupportActionBar(mToolbar);
        mToolbar.setTitle("控件学习");

        //2.注册广播
        registerBroadcastReceiver();
        //3.发送广播
        mButton.setOnClickListener(this);

        mLoadImage.setOnClickListener(this);

        mRecycle.setOnClickListener(this);

        mCardView.setOnClickListener(this);

        mNoti.setOnClickListener(this);

        mTo.setOnClickListener(this);

        mTextInput.setOnClickListener(this);

        mTabLayout.setOnClickListener(this);

        mNavigation.setOnClickListener(this);

        mHideToolbar.setOnClickListener(this);

        mHideToolbar2.setOnClickListener(this);

        mBehavior1.setOnClickListener(this);

        mBehavior2.setOnClickListener(this);


    }

    private void registerBroadcastReceiver() {
        IntentFilter filter = new IntentFilter();
        filter.addAction(ACTION_NAME);
        registerReceiver(mBroadcastReceiver,filter);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.id_cardview:
                startActivity(new Intent(MainActivity.this,CardViewActivity.class));
                break;
            case R.id.button:
                Intent in = new Intent(ACTION_NAME);
                sendBroadcast(in);
                break;
            case R.id.showimage:
                startActivity(new Intent(MainActivity.this, TextAsyncTask.class));
                break;
            case R.id.id_recycle:
                startActivity(new Intent(MainActivity.this,RecyleActivity.class));
                break;
            case R.id.id_noti:
                startActivity(new Intent(MainActivity.this,NotificationActivity.class));
                break;
            case R.id.id_toolbar:
                startActivity(new Intent(MainActivity.this,MyToolbarActivity.class));
                break;
            case R.id.id_textinput:
                startActivity(new Intent(MainActivity.this,TextInputActivity.class));
                break;
            case R.id.id_tabLayout:
                startActivity(new Intent(MainActivity.this,TabLayoutActivity.class));
                break;
            case R.id.id_navigation:
                startActivity(new Intent(MainActivity.this,NavigationActivity.class));
                break;
            case R.id.id_hideToolbar:
                startActivity(new Intent(MainActivity.this,CoordicatorActivity.class));
                break;
            case R.id.id_collapsing:
                startActivity(new Intent(MainActivity.this,CollapsingToolbarActivity.class));
                break;
            case R.id.id_behavior_one:
                startActivity(new Intent(MainActivity.this,BehaviorOneActivity.class));
                break;
            case R.id.id_behavior_two:
                startActivity(new Intent(MainActivity.this,BehaviorTwoActivity.class));
                break;

        }
    }
}
